import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  page = '/msg-push-service/msgReceiver/page',
  get = '/msg-push-service/msgReceiver/get',
  save = '/msg-push-service/msgReceiver/save',
  edit = '/msg-push-service/msgReceiver/update',
  delete = '/msg-push-service/msgReceiver/delete',
  deleteBatch = '/msg-push-service/msgReceiver/deleteBatch',
  sendCaptcha = '/msg-push-service/msgReceiver/sendCaptcha',
  checkCaptcha = '/msg-push-service/msgReceiver/checkCaptchaFromAdmin',
  getWxMpQrcode = '/msg-push-service/msgReceiver/getWxMpQrcode',

  listSubscribeMsg = '/msg-push-service/msgReceiver/listSubscribeMsg',
}

/**
 * 列表
 * @param params
 */
export const pageReceiver = (params) => defHttp.get({url: Api.page, params});
export const getReceiver = (params) => defHttp.get({url: Api.get, params});
export const sendCaptcha = (params) => defHttp.post({url: Api.sendCaptcha, params});
export const checkCaptcha = (params) => defHttp.post({url: Api.checkCaptcha, params});

/**
 * 删除消息接收人
 */
export const deleteRole = (params, handleSuccess) => {
  return defHttp.delete({url: Api.delete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除消息接收人
 * @param params
 */
export const batchDeleteRole = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新消息接收人
 * @param params
 */
export const saveOrUpdateReceiver = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


export const listSubscribeMsg = (params) => defHttp.get({url: Api.listSubscribeMsg, params});
export const getWxMpQrcode = () => defHttp.get({url: Api.getWxMpQrcode, params: {}});
